package aliyunCli

import (
	"fmt"
	"tushare/conf"

	openapi "github.com/alibabacloud-go/darabonba-openapi/client"
	ecs20140526 "github.com/alibabacloud-go/ecs-20140526/v2/client"
	"github.com/alibabacloud-go/tea/tea"
)

type CreateKeyPair struct{}

func (ckp CreateKeyPair) createClient(accessKeyId *string, accessKeySecret *string) (_result *ecs20140526.Client, _err error) {
	config := &openapi.Config{
		// 您的AccessKey ID
		AccessKeyId: accessKeyId,
		// 您的AccessKey Secret
		AccessKeySecret: accessKeySecret,
	}
	// 访问的域名
	config.Endpoint = tea.String("ecs-cn-hangzhou.aliyuncs.com")
	_result = &ecs20140526.Client{}
	_result, _err = ecs20140526.NewClient(config)
	return _result, _err
}

func (ckp CreateKeyPair) CreateKeyPair(keyPairName string) {
	client, err := ckp.createClient(tea.String(conf.AccessKeyID), tea.String(conf.AccessKeySecret))

	request := &ecs20140526.CreateKeyPairRequest{
		RegionId:    tea.String("cn-hangzhou"),
		KeyPairName: tea.String(keyPairName),
	}

	res, err := client.CreateKeyPair(request)
	if err != nil {
		fmt.Print(err.Error())
	}
	privateKeyBody := *res.Body.PrivateKeyBody
	fmt.Println(privateKeyBody)
}
